import { message } from 'antd';
export default {
  namespace: 'hdst',
  state: {
    mainZmcParams: [], // 控制器参数设置
    configParams: [], // 设备设置参数,包括相机还有其他的一些参数
  },
  effects: {
    *handleSettingsUpdate({ payload }, { call, put }) {
      yield put({
        type: 'getMainZmcParams',
      });
    },
    *getMainZmcParams({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'mainZmc',
        'web_request_get_main_zmc_params',
        []
      );
      console.log('in web_request_get_main_zmc_params msg = ', response);
      yield put({
        type: 'updateMainZmcParams',
        payload: response,
      });
    },
    *saveMainZmcParams({ payload }, { call, put }) {
      const response = yield call(window.eel.run_py, 'mainZmc', 'web_request_save_main_zmc_params', [
        payload,
      ]);
      if (response === 'ok') {
        message.success('保存成功!');
      } else {
        message.error('保存失败,', response);
      }
      yield put({
        type: 'getMainZmcParams',
      });
    },
  },
  reducers: {
    updateMainZmcParams(state, action) {
      return {
        ...state,
        mainZmcParams: action.payload,
      };
    },
  },
};
